
<?php	
	
	require_once('../../lib/'.'BaseDir.inc.htm');	
	
	require_once (EIU_CLASS.'IOClass.htm');	
	
	set_time_limit(30);
	//Define the max number of row on a page	
	$data["dataSearch"]["TimeStart"] = date("h:i:s:u");
	
	$imExid = $_POST["imExid"];
	$fromdate = $_POST["fromdate"];
	$todate = $_POST["todate"];
	$impPer = $_POST["impPer"];
	$expPer = $_POST["expPer"];
	$Remark = "";
	
	if($fromdate == "")	$fromdate = "0000-00-00";
	else $fromdate = date("Y-m-d", strtotime($fromdate));	
	
	if($todate == "")	$todate = "2900-01-01";
	else $todate = date("Y-m-d", strtotime($todate));
	
	$ioObj = new io_class();	
	
	//Lấy danh sách IO
	//$ioList = $ioObj->getIOList($imExid,$fromdate,$todate,$impPer,$expPer,$Remark);	
	$InvoiceID = "";
	$RecvNoteCode = $imExid;
	$FromDate = $fromdate;
	$ToDate = $todate;
	$ReceiptPerson = $impPer;
	$DeliveryPerson = $expPer;
	$RecvRoom = "";
	$Note = "";
	$ioList = $ioObj->getInvcList($InvoiceID,$RecvNoteCode,$FromDate,$ToDate,$ReceiptPerson,$DeliveryPerson,$RecvRoom,$Note);
	
	//Xuất ra theo Paging
	if(isset($_POST['page']) && !empty($_POST['page'])){
		$startLimit = ($_POST['page']-1)*NUMBER_ROW_ON_DSPNK_SCREEN;
		$finishLimit = $startLimit+NUMBER_ROW_ON_DSPNK_SCREEN;
	}	
	
	//print_r($ioList);

	$totalRow = 0;
	if($ioList)
	{
		$totalRow = count($ioList);
	}
	
	$data["dataSearch"]["start"] =  $startLimit;
	$data["dataSearch"]["finish"] =  $finishLimit;
	
	//echo $startLimit." - ".$finishLimit;
	
	$data["dataSearch"]["Count"] = $totalRow;
	$data["dataSearch"]["Result"] = "";
	
	$j = 0;
	for($i=$startLimit;$i<$finishLimit;$i++){		
		if($ioList[$i])
		{
			$data["dataSearch"]["Result"][$j]["ioCode"] = $ioList[$i]->{"RecvNoteCode"};
			$data["dataSearch"]["Result"][$j]["createdDate"] = $ioList[$i]->{"ReceiptDate"};
			$data["dataSearch"]["Result"][$j]["receiptPerson"] = ($ioList[$i]->{"ReceiptPerson"});
			$data["dataSearch"]["Result"][$j]["deliveryPerson"] = ($ioList[$i]->{"DeliveryPerson"});
			$data["dataSearch"]["Result"][$j]["note"] = $ioList[$i]->{"Remark"};
			$data["dataSearch"]["Result"][$j]["invcNo"] = $ioList[$i]->{"InvcNo"};
			$data["dataSearch"]["Result"][$j]["DiscountVND"] = $ioList[$i]->{"DiscountVND"};
			$data["dataSearch"]["Result"][$j]["SubTotalVND"] = $ioList[$i]->{"SubTotalVND"};
			$data["dataSearch"]["Result"][$j]["VATAmountVND"] = $ioList[$i]->{"VATAmountVND"};
			$data["dataSearch"]["Result"][$j]["TotalVND"] = $ioList[$i]->{"TotalVND"};
			$data["dataSearch"]["Result"][$j]["DisPercent"] = $ioList[$i]->{"DisPercent"};
			$data["dataSearch"]["Result"][$j]["VATPercent"] = $ioList[$i]->{"VATPercent"};
			
			$j++;
		}		
	}		
	$data["dataSearch"]["TimeFinish"] = date("h:i:s:u");
	$json = json_encode($data["dataSearch"]);
	
	echo $json;	
	
?>